In [1]:
import wfdb
import numpy as np
import matplotlib.pyplot as plt
import sys
sys.path.insert(0, '/home/scidb/HeartRatePatterns/Python')
#QRSDetectorOffline.py
from QRSDetectorOffline import QRSDetectorOffline
In [2]:
folder = "p05/p050140"
waveform = "p050140-2188-07-26-05-51"
sig, fields = wfdb.srdsamp(waveform,pbdir='mimic3wdb/matched/'+folder, sampto=10000)
In [3]:
print("signame: " + str(fields['signame']))
print("units: " + str(fields['units']))
print("fs: " + str(fields['fs']))
print("comments: " + str(fields['comments']))
print("fields: " + str(fields))
In [4]:
signalII = None
try:
signalII = fields['signame'].index("II")
except ValueError:
print("List does not contain value")
if(signalII!=None):
print("List contain value")
In [5]:
#array = wfdb.processing.normalize(x=sig[:, signalII], lb=-2, ub=2)
array = sig[:, signalII]
array = array[~np.isnan(sig[:, signalII])]
arrayNun = np.trim_zeros(array)
array = np.nan_to_num(array)
Save the Frame Secuence
In [6]:
fs = fields['fs']
fs
Out[6]:
Create Numpy Array
In [7]:
npArray = np.array(array)
npArray
Out[7]:
check sig:
In [8]:
plt.plot(npArray)
plt.show()
In [9]:
len(np.array(npArray))
Out[9]:
In [10]:
sha = np.arange(npArray.shape[0])
In [11]:
test = np.stack((sha, np.nan_to_num(npArray))).T
In [12]:
ecg_data_path = 'ecg_data/'+waveform+'.csv'
np.savetxt(ecg_data_path, test, delimiter=',')
qrs_detector = QRSDetectorOffline(ecg_data_path=ecg_data_path, verbose=True,log_data=True, plot_data=True,
show_plot=True,signal_frequency=fs)
In [19]:
first = qrs_detector.qrs_peaks_indices[0]
someLater = qrs_detector.qrs_peaks_indices[20]
Out[19]:
Small array
In [13]:
small = npArray[first:someLater]
sha = np.arange(small.shape[0])
In [14]:
plt.plot(small)
plt.show()
In [15]:
test = np.stack((sha, np.nan_to_num(small))).T
test
Out[15]:
In [16]:
ecg_data_path = 'ecg_data/small.csv'
np.savetxt(ecg_data_path, test, delimiter=',')
qrs_detector = QRSDetectorOffline(ecg_data_path=ecg_data_path, verbose=True,log_data=True, plot_data=True,
show_plot=True,signal_frequency=fs)
In [17]:
first = qrs_detector.qrs_peaks_indices[2]
someLater = qrs_detector.qrs_peaks_indices[6]
small = np.delete(qrs_detector.ecg_data_detected[first:someLater],0,1)
plt.plot(small)
plt.show()
In [ ]: